package com.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.TableGenerator;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.core.protocols.IKVObject;
import com.core.utils.LocalizableString;

@Entity
public class TabSheetItem
        implements IKVObject {

	private Integer         id;
	private UserContextName userContextNameToExecute;



	public TabSheetItem() {

	}



	@Id
	@TableGenerator(allocationSize = 10, table = "Generators", pkColumnName = "generatorName", pkColumnValue = "generatorTabsheetItem", name = "generatorTabsheetItem")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "generatorTabsheetItem")
	public Integer getId () {

		return id;
	}



	public void setId ( Integer id ) {

		this.id = id;
	}

	private String       name;
	private String       servletNameToExecute;
	private String       imgAbsoluteAddress;
	private String       jspNameInContext;
	private ActionScript actionScript;



	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	public ActionScript getActionScript () {

		return actionScript;
	}



	public void setActionScript ( ActionScript actionScript ) {

		this.actionScript = actionScript;
	}



	public String getName () {

		return name;
	}



	public void setName ( String name ) {

		this.name = name;
	}

	private Set <UserContextName> userContextNameVisibleIn = new HashSet <UserContextName>();



	@ManyToOne
	public UserContextName getUserContextNameToExecute () {

		return userContextNameToExecute;
	}



	public void setUserContextNameToExecute ( UserContextName userContextNameToExecute ) {

		this.userContextNameToExecute = userContextNameToExecute;
	}



	@ManyToMany
	@NotFound(action = NotFoundAction.IGNORE)
	public Set <UserContextName> getUserContextNameVisibleIn () {

		return userContextNameVisibleIn;
	}



	public void setUserContextNameVisibleIn ( Set <UserContextName> userContextNameVisibleIn ) {

		this.userContextNameVisibleIn = userContextNameVisibleIn;
	}



	public String getServletNameToExecute () {

		return servletNameToExecute;
	}



	public void setServletNameToExecute ( String servletNameToExecute ) {

		this.servletNameToExecute = servletNameToExecute;
	}



	public String getImgAbsoluteAddress () {

		return imgAbsoluteAddress;
	}



	public void setImgAbsoluteAddress ( String imgAbsoluteAddress ) {

		this.imgAbsoluteAddress = imgAbsoluteAddress;
	}



	public String getJspNameInContext () {

		return jspNameInContext;
	}



	public void setJspNameInContext ( String jspNameInContext ) {

		this.jspNameInContext = jspNameInContext;
	}



	@Override
	public void assignTo ( IKVObject object ) {

	}



	@Override
	public KeyValue idValue () {

		String strIdValue = this.getId().toString();
		return new KeyValue(this.fieldNameAsId(), strIdValue, false);

	}



	@Override
	public String fieldNameAsId () {

		return "id";
	}



	@Override
	public KeyValue nameValue () {

		String strIdValue = this.getName().toString();
		return new KeyValue(this.fieldNameAsName(), strIdValue, false);

	}



	@Override
	public String fieldNameAsName () {

		return "name";
	}



	public String localizableDescription () {

		return LocalizableString.sharedInstance().localizable("entity.TabSheetItem.description");
	}
}
